<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

<?php
$id = $_REQUEST['_d'];
$page = $_REQUEST['page'];

if($_REQUEST['_a'] != "u" && $_REQUEST['_a'] != "d")
{
$q = mysql_fetch_array(mysql_query("select * from news where Id='$id'"));
?>
<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>

<form name="up" action="index.php?tc=news_view&_d=<?php echo $id;?>&page=<?php echo $page;?>&_a=u" method="post">
<table width="99%" align="center" border="0"  class="list" cellpadding="5">
<thead>
<tr>
	<td colspan="2" align="left">
        <div style="float:left" class="righthead">News</div>
        <div style="float:right"><a href="index.php?tc=news&page=<?php echo $page;?>" class="back">Back</a></div>
    </td>
</tr>
</thead>
<tr>
	<td align="right" width="150">Title</td>
    <td align="left"><input type="text" name="title" value="<?php echo $q['Title'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="150">Name</td>
    <td align="left"><input type="text" name="name" value="<?php echo $q['Name'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="150">Organization Name</td>
    <td align="left"><input type="text" name="org" value="<?php echo $q['Organisation'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="150">Email</td>
    <td align="left"><input type="text" name="email" value="<?php echo $q['Email'];?>"  /></td>
</tr>
<tr>
	<td align="right" width="150">Category</td>
    <td align="left">
			<select name="category">
            	<option value="">--Select--</option>
                <option value="Other News Items" <?php if($q["Category"]=="Other News Items") echo "selected";?>>Other News Items</option>
                <option value="Shire News" <?php if($q["Category"]=="Shire News") echo "selected";?>>Shire News</option>
                <option value="Educational News" <?php if($q["Category"]=="Educational News") echo "selected";?>>Educational News</option>
                <option value="Health Matters" <?php if($q["Category"]=="Health Matters") echo "selected";?>>Health Matters</option>
                <option value="Electorate News" <?php if($q["Category"]=="Electorate News") echo "selected";?>>Electorate News</option>
                <option value="Mining News" <?php if($q["Category"]=="Mining News") echo "selected";?>>Mining News</option>
            </select>
    </td>
</tr>
<tr>
	<td align="right" width="150">News</td>
    <td align="left">
    <textarea name="maincont" id="maincont" class="textarea" cols="45" rows="8"><?php echo stripslashes($q["News"]);?></textarea>
        <script type="text/javascript">CKEDITOR.replace( 'maincont',{skin : 'kama'});</script>
   
</tr>
<tr>
	<td align="right" width="150">Content</td>
    <td align="left"><a href="../uploads/news/<?php echo $q["Content"];?>"><?php echo $q["Content"];?></a></td>
</tr>
<tr>
	<td align="right" width="150">Authorised</td>
    <td align="left">
        <input  name="authorised" type="radio" value=1 <?php if($q["Authorised"] == 1) echo "checked";?> />&nbsp;Yes&nbsp;&nbsp;
		<input  name="authorised" type="radio" value=0 <?php if($q["Authorised"] == 0) echo "checked";?> />&nbsp;No
    </td>
</tr> 
<tr>
	<td align="right" width="150">Created Date</td>
    <td align="left"><?php echo $q["CreatedDate"];?></td>
</tr> 
<tr>
	<td align="right" width="150">Status</td>
    <td align="left">
    	<select name="status">
        	<option value="0" <?php if($q["Status"]==0) echo "selected";?>>Pending</option>
            <option value="1" <?php if($q["Status"]==1) echo "selected";?>>Approved</option>
       	</select>     
    </td> 
</tr> 
<tr>
	<td colspan="2" style="padding-left:155px;">
    	<input type="submit" value="Update" >&nbsp;&nbsp;
        
    </td>
</tr>        
</table>   
</form> 
<?php
}

if($_REQUEST['_a']=="u")
{
	$status = $_POST['status'];
	$title = $_POST['title'];
	$name = $_POST['name'];
	$org = $_POST['org'];
	$email = $_POST['email'];
	$news = mysql_real_escape_string($_POST['maincont']);
	$category = $_POST['category'];
	$authorised = $_POST['authorised'];
	
	
	
	mysql_query("update news set Name='$name', Email='$email', Organisation='$org', Title='$title', News='$news', Status='$status', Category='$category', Authorised='$authorised', ApprovedDate=now() where Id='$id'");
	//header("location:index.php?tc=news_view&_d=$id&page=$page&_s=1");
	echo "<script>window.location='index.php?tc=news_view&_d=$id&page=$page&_s=1'</script>";
}
if($_REQUEST['_a']=="d")
{
	$q = mysql_fetch_array(mysql_query("select * from news where Id='$id'"));
	if($q["Content"] != "")
	{
		@unlink("../uploads/news/".$q["Content"]);	
	}
	mysql_query("delete from news where Id='$id'");
	//header("location:index.php?tc=news&page=$page&_s=2");
	echo "<script>window.location='index.php?tc=news&page=$page&_s=2'</script>";
}
?>